from typing import Set

from gui.utils.colors import RED
from state.block import WorldBlock
from state.resource import ResPanel
from state.tech_panel import TechPanel


class Player:
    def __init__(self, name, color=RED):
        self.name = name
        self.blocks: Set[WorldBlock] = set()
        self.color = color

        self.res_panel = ResPanel()
        self.tech_panel = TechPanel()
        self.discover_blocks: Set[(int, int)] = set()

    def add_block(self, block: WorldBlock):
        self.blocks.add(block)
        block.player = self.name
        self.res_panel.update_for_block(block)

    def discover_block(self, block: WorldBlock):
        self.discover_blocks.add((block.row, block.col))

    def check_visible(self, block: WorldBlock):
        return block.pos in self.discover_blocks

    def check_belong_me(self, block: WorldBlock):
        return block in self.blocks
